#!/usr/bin/python

# Python script for Nepomuk firefox
print "Script ontoTree.py in the position"

#get the argument from parent window
arg0 = window.arguments[0]
document.getElementById("uriLabel").setAttribute("value",arg0)


# attach TheNepomukWhisperer to the document
from the_nepomuk_whisperer import TheNepomukWhisperer
document.NEPO = TheNepomukWhisperer(ONTOLOGIES_STORAGE_FILE)

# retrive the Properties and Class
theProps = document.NEPO.pimo.getPropertiesOfUri(arg0)
theClasses = document.NEPO.pimo.getClassesOfUri(arg0)

# Create the top node
children0 = document.createElement('treechildren')
children1 = document.createElement('treechildren')
#Create the node for 'Property' and 'Class'
children2 = document.createElement('treechildren')
children3 = document.createElement('treechildren')
	
# Add items to 'Class' node
for aclass in theClasses:
	item1 = document.createElement('treeitem')
	row1 = document.createElement('treerow')
	i=1
	tiptext = ""
	for column in aclass:
		i=i+1
		if i==2:
			tiptext = column
			#print tiptext
			continue
		cell1 = document.createElement('treecell')
		cell1.setAttribute('label', column)
		row1.setAttribute('value', tiptext)
		row1.appendChild(cell1)

	item1.appendChild(row1)
	children2.appendChild(item1)

# Add items to 'Property' node
for prop in theProps:
	item2 = document.createElement('treeitem')
	row2 = document.createElement('treerow')
	i=1
	for column in prop:
		i=i+1
		if i==2:
			tiptext = column
			#print tiptext
			continue
		#if i!=2:
		cell2 = document.createElement('treecell')
		cell2.setAttribute('label', column)
		row2.setAttribute('value', 'tiptext')
		row2.appendChild(cell2)

	item2.appendChild(row2)
	children3.appendChild(item2)

# Fill up the 'Class' node
item = document.createElement('treeitem')
item.setAttribute('container', 'true')
item.setAttribute('open', 'true')
row = document.createElement('treerow')
cell = document.createElement('treecell')
cell.setAttribute('label', 'Class')

row.appendChild(cell)
item.appendChild(row)
item.appendChild(children2)
children0.appendChild(item)

# Fill up the 'Property' node
item = document.createElement('treeitem')
item.setAttribute('container', 'true')
item.setAttribute('open', 'true')
row = document.createElement('treerow')
cell = document.createElement('treecell')
cell.setAttribute('label', 'Property')

row.appendChild(cell)
item.appendChild(row)
item.appendChild(children3)
children1.appendChild(item)

# Fill up the tree
document.getElementById("ontotree1").appendChild(children0)
document.getElementById("ontotree2").appendChild(children1)